package pattern.singleton;

/**
 * 懒汉式
 */
public class Singleton2 {
    // 私有化构造方法
    private Singleton2(){}

    private static Singleton2 singleton2;

    // 由于懒汉式是非线程安全的，所以要加上线程锁
    public static synchronized Singleton2 getInstance() {
        if (singleton2 == null) {
            singleton2 = new Singleton2();
        }
        return singleton2;
    }
}
